

#include <sys/socket.h>
#include <arpa/inet.h>
#include <unistd.h>
#include <errno.h>

#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <string.h>

#define MAXLINE 1500

void dg_cli(FILE *, int sockfd, struct sockaddr *, socklen_t);

void dg_cli(FILE * fp, int sockfd, struct sockaddr * sa, socklen_t servlen){

    size_t n = 0UL;

    char sendline[MAXLINE], recvline[MAXLINE + 1];

    struct timeval tv;
    tv.tv_sec  = 5;
    tv.tv_usec = 0;

    // socket option
    setsockopt(sockd, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(tv));


    while(fgets(sendline, MAXLINE, fp) != NULL){

	sendto(sockfd, sendline, strlen(sendline), 0, sa, servlen);

	n = recvfrom(sockfd, recvline, MAXLINE, 0, NULL, NULL);

	if(n < 0){

	    if(errno == EWOULDBLOCK){

		fprintf(sdterr, "socket timeout\n");
		continue;
	    }else{

		printf("recvfrom terminate\n");
		return;
	    }
	}
    }
}



